<template>
	<view>
		<view class="info_box">
			<view class="info_title">姓名</view>
			<view class="info_context">***</view>
		</view>
		<view class="info_box">
			<view class="info_title">年龄</view>
			<view class="info_context">{{user.age}}</view>
		</view>
		<view class="info_box">
			<view class="info_title">舌象</view>
			<view class="info_context" @click="show_shexiang">点击查看</view>
		</view>
		<view class="info_box">
			<view class="info_title">其他医学类诊断资料</view>
			<view class="info_context" @click="show_other_picture">点击查看</view>
		</view>
		<view class="info_box" v-for="(zd_item,index) in user.zhenduan">
			<view class="info_title">诊断{{index+1}}</view>
			<view class="info_context">{{zd_item.name}}</view>
			<view class="info_context">{{user.name}}</view>
		</view>
		<view class="btn_list">
			<u-button @click="fenpeiys(user.id)">分配</u-button>
			<u-button>返回</u-button>
		</view>
		<u-picker
			v-model="fenpei_area.show"
			mode="selector"
			:range="doc_list"
			range-key="name"
			@confirm="picker_confirm"
		></u-picker>
	</view>
</template>

<script>
	import { get_zhenduan_info,get_doc_tree,fenpei_doc } from '@/util/api/api.js';
	
	export default {
		data() {
			return {
				url: "/index.php/html5/zhenduan/get_zhenduan_info",
				get_doc_tree_url:'/index.php/html5/zhenduan/get_doc_tree',
				fenpei_doc_url:'/index.php/html5/zhenduan/fenpei_doc',
				user:{
					age:32,
					tongue:'',
					other_picture:[],
					zhenduan:[

					]
				},
				doc_list:[
				],
				fenpei_area:{
					show:false,
					zdid:0,
					doc_id:0,
				}
			}
		},
		onLoad(e) {
			this.id = e.id
			this.get_zhenduan_info()
			this.get_doc_list()
		},
		methods: {
			get_zhenduan_info(){
				let that = this
				
				get_zhenduan_info({id:that.id}).then((res)=>{
					if (res.code==200) {
						let info = res.data
						
						that.user.age = info.user.age
						that.tongue = info.tongue
						that.other_picture = info.other_picture
						
						let text = {}
						if(info.text1){
							text = JSON.parse(info.text1)
							that.user.zhenduan = text.classesList
							console.log(that.user.zhenduan)
						}
					} else{
						that.showToast(res.message)
					}
				})
			},
			show_shexiang(){
				uni.previewImage({
					urls:[this.user.tongue]
				})
			},
			show_other_picture(){
				uni.previewImage({
					urls:[this.user.tongue]
				})
			},
			get_doc_list(){
				let that = this
				
				get_doc_tree().then((res)=>{
					if (res.code==200) {
						let doc_list = res.data
						
						for(let doc_index in doc_list){
							doc_list[doc_index].name = doc_list[doc_index].name+'('+doc_list[doc_index].dep_name+')'
						}
						
						console.log(doc_list)
						
						that.doc_list = doc_list
					} else{
						// that.showToast(res.message)
					}
				})
			},
			init_fenpei_area(){
				this.fenpei_area={
					show:false,
					zdid:0,
					doc_id:0
				}
			},
			fenpeiys(id){
				this.fenpei_area.zdid = id
				this.fenpei_area.show = true
			},
			picker_confirm(e){
				let that = this
				
				let data = {
					zhenduan_id:that.id,
					doc_id:that.doc_list[e].id
				}
				
				fenpei_doc(data).then((res)=>{
					if (res.data.code==200) {
						uni.showToast({
							title: '将患者分配给'+that.doc_list[e].name,
							duration: 2000
						});
						uni.switchTab({
							url:'/pages/fenpei/fenpeilist'
						})
					} else{
						// that.showToast(res.message)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	padding: 25rpx;
}
.info_box{
	border-bottom: 2rpx solid #F5F5F5;
	.info_title{
		font-size: 30rpx;
		font-weight: bold;
		color: #666666;
		line-height: 77rpx;
	}

	.info_context{
		font-size: 30rpx;
		font-weight: bold;
		color: #666666;
		line-height: 77rpx;
	}
}

.btn_list{
	width: 700rpx;
	margin-top: 140rpx;
	display: flex;
	
	.u-btn{
		width: 300rpx;
		height: 88rpx;
		background: #15BBA2;
		border-radius: 44px;
		color: #FFFFFF;
	}
	
	.u-btn:active{
		width: 300rpx;
		height: 88rpx;
		background: #15BBA2;
		border-radius: 44px;
		color: #FFFFFF;
	}
}
</style>
